package com.shadt.cloud.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shadt.cloud.entity.CloudBranch;
import com.shadt.cloud.entity.User;
import com.shadt.cloud.service.AdminService;
import com.shadt.cloud.service.BranchService;
import com.shadt.cloud.service.SMSService;
import com.shadt.cloud.service.UserService;
import com.shadt.cloud.vo.BranchChannelVo;
import com.shadt.cloud.vo.BranchVo;
import com.shadt.cloud.vo.ChannelVo;
import com.shadt.core.controller.BaseController;
import com.shadt.core.model.Json;

/**
 * 后台控制器
 * @author SongR
 *
 */
@Controller
@RequestMapping(value="/admin")
public class AdminController extends BaseController{

	Logger log = Logger.getLogger(this.getClass());
	@Autowired
	AdminService service;
	
	@Autowired
	UserService uservice;
	
	@Autowired
	BranchService bservice;
	
	@Autowired
	SMSService sservice;
	
	
	/**
	 * 登录页面跳转
	 */
	@RequestMapping(value="/loginpage")
	public String loginPage(HttpSession session){
		User u = (User) session.getAttribute("userinfo");
		if(null!=u){
			return "h/index";
		}
		return "h/login";
	}
	
	/**
	 * 注册页面
	 * @return
	 */
	@RequestMapping(value="/registerpage")
	public String registerPage(){
		return "h/register";
	}
	
	/**
	 * 验证值是否存在
	 * @param value
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/checkname")
	public boolean checkName(String name){
		boolean t = false;
		try {
			t = service.checkName(name.trim());
		} catch (Exception e) {
			log.error("验证平台名称接口异常！",e);
			e.printStackTrace();
		}
		return t;
	}
	
	/**
	 * 注册
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/register",method=RequestMethod.POST)
	public Json register(HttpSession session,User user){
		Json j = new Json();
		try {
			User b = service.register(user);
			if(b!=null){
				j.setSuccess(true);
				j.setMsg("注册成功！");
				j.setObj(b);
			}else{
				j.setMsg("注册失败！");
			}
		} catch (Exception e) {
			j.setMsg("注册接口异常！");
			log.error("注册接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 登录
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public Json login(HttpSession session,User user){
		Json j = new Json();
		try {
			User u= service.login(user);
			if(u!=null){
				j.setSuccess(true);
				j.setMsg("登录成功！");
				session.setAttribute("userinfo", u);
			}else{
				j.setMsg("用户名或密码不正确！");
			}
		} catch (Exception e) {
			j.setMsg("接口异常！");
			log.error("登录接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 跳转到首页
	 * @return
	 */
	@RequestMapping(value="/indexpage")
	public String indexPage(HttpSession session){
		User u = (User) session.getAttribute("userinfo");
		if(null!=u){
			return "h/index";
		}
		return "h/login";
	}
	/**
	 * 修改信息
	 * @return
	 */
	public Json edit(){
		Json j = new Json();
		
		return j;
	}
	
	/**
	 * 退出
	 * @return
	 */
	@RequestMapping(value="/logout",method=RequestMethod.GET)
	public String logout(HttpSession session){
		try {
			User u = (User)session.getAttribute("userinfo");
			if(null!=u){
				boolean lo = service.logout(u);
				if(lo){
					
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("退出异常！",e);
		}
		session.invalidate();
		return "h/login";
	}
	/*****************************************/
	/**
	 * 参数验证
	 * @param session
	 * @param key
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/check/{key}",method={RequestMethod.GET,RequestMethod.POST})
	public Json check(HttpSession session,HttpServletRequest request,@PathVariable String key){
		Json j = new Json();
		try {
			if(key.equals("phone")){
				String phone = request.getParameter("phone");
				if(null==phone||"".equals(phone)){
					j.setMsg("手机号码不能为空！");
				}else{
					User u = uservice.getByPhone(phone);
					if(null!=u){
						j.setMsg("手机号已存在！");
					}else{
						j.setMsg("该手机号可以注册");
						j.setSuccess(true);
					}
				}
			}else if(key.equals("username")){
				String username = request.getParameter("username");
				if(null==username||"".equals(username)){
					j.setMsg("用户名不能为空！");
				}else{
					User u = uservice.getByUserName(username);
					if(null!=u){
						j.setMsg("用户名已存在！");
					}else{
						j.setMsg("用户名可以注册");
						j.setSuccess(true);
					}
				}
			}else if(key.equals("code")){
				String phone = request.getParameter("phone");
				String code = request.getParameter("code");
				if(null==code||"".equals(code)){
					j.setMsg("验证码不能为空！");
				}else{
					boolean ischeck = sservice.checkCode(phone, code);
					if(ischeck){
						j.setMsg("验证通过！");
						j.setSuccess(true);
					}else{
						j.setMsg("验证失败！");
					}
				}
			}else if(key.equals("branchname")){
				String name = request.getParameter("name");
				if(null==name||"".equals(name)){
					j.setMsg("平台名称不能为空！");
				}else{
					BranchVo vo = bservice.checkBranch(name);
					if(null!=vo){
						j.setMsg("该平台已存在！");
					}else{
						j.setMsg("该平台可以注册");
						j.setSuccess(true);
					}
				}
			}
		} catch (Exception e) {
			j.setMsg("接口异常！");
			log.error("接口异常！",e);
			e.printStackTrace();
		}
		
		return j;
	}
	
	/*****************************************/
	/**
	 * 平台权限申请页面
	 * @return
	 */
	@RequestMapping(value="/branch/branchapply")
	public String branchApplyPage(){
		return "h/branchapply";
	}
	
	/**
	 * 获取所有待审核平台列表
	 * @param session
	 * @param aoData
	 * @param type
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/get/{type}",method={RequestMethod.GET,RequestMethod.POST})
	public Json getBranch(HttpSession session,String aoData,@PathVariable String type){
		Json j = new Json();
		try {
			aoData = aoData.replaceAll("&quot;", "\"");
			User u = (User) session.getAttribute("userinfo");
			JSONObject o = JSONObject.parseObject(aoData);
			String search = o.getString("sSearch");
			Integer start = o.getInteger("iDisplayStart");
			Integer length = o.getInteger("iDisplayLength");
			List<BranchVo> vos = bservice.getBranch(search,start,length,u,type);
			Map<String,Object> m = new HashMap<String,Object>();
			m.put("sEcho", o.getString("sEcho"));
			m.put("iTotalRecords", vos.size());
			m.put("iTotalDisplayRecords",bservice.getBranchCount(search,u,type));
			m.put("aaData", vos);// 要以JSON格式返回
			if(m.size()>0){
				j.setObj(m);
				j.setSuccess(true);
				j.setMsg("成功获取平台列表！");
			}else{
				j.setMsg("该用户暂无平台列表！");
				j.setSuccess(true);
			}
		} catch (Exception e) {
			j.setMsg("获取平台列表接口异常！");
			log.error("获取平台列表接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	
	
	
	/**
	 * 获取商户
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/get",method=RequestMethod.GET)
	public Json getBranch(HttpSession session){
		Json j = new Json();
		try {
			User u = (User)session.getAttribute("userinfo");
			List<BranchVo> vos = service.getBranch(u.getId(),u.getType());
			j.setSuccess(true);
			if(vos.size()>0){
				j.setMsg("成功获取商户列表！");
				j.setObj(vos);
			}else{
				j.setMsg("暂无商户！");
			}
		} catch (Exception e) {
			j.setMsg("获取商户列表接口异常！");
			log.error("获取商户列表接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 获取平台
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/get",method={RequestMethod.GET,RequestMethod.POST})
	public Json getBranch(HttpSession session,String aoData){
		Json j = new Json();
		try {
			aoData = aoData.replaceAll("&quot;", "\"");
			User u = (User) session.getAttribute("userinfo");
			JSONObject o = JSONObject.parseObject(aoData);
			String search = o.getString("sSearch");
			Integer start = o.getInteger("iDisplayStart");
			Integer length = o.getInteger("iDisplayLength");
			List<BranchVo> vos = bservice.getBranch(search,start,length,u);
			Map<String,Object> m = new HashMap<String,Object>();
			m.put("sEcho", o.getString("sEcho"));
			m.put("iTotalRecords", vos.size());
			m.put("iTotalDisplayRecords",bservice.getBranchCount(search,u));
			m.put("aaData", vos);// 要以JSON格式返回
			if(m.size()>0){
				j.setObj(m);
				j.setSuccess(true);
				j.setMsg("成功获取平台列表！");
			}else{
				j.setMsg("该用户暂无平台列表！");
				j.setSuccess(true);
			}
		} catch (Exception e) {
			j.setMsg("获取平台列表接口异常！");
			log.error("获取平台列表接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 添加平台
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/add",method=RequestMethod.POST)
	public Json addBranch(HttpSession session,CloudBranch branch){
		Json j = new Json();
		try {
			User u = (User)session.getAttribute("userinfo");
			BranchVo vo = bservice.add(u,branch);
			if(null!=vo){
				j.setMsg("平台注册成功！");
				j.setObj(vo);
				j.setSuccess(true);
			}else{
				j.setMsg("平台注册失败！");
			}
		} catch (Exception e) {
			j.setMsg("注册平台接口异常！");
			log.error("平台注册接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	
	@RequestMapping(value="/branch/index")
	public String branchPage(){
		return "h/branch";
	}
	/**
	 * 编辑平台
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/edit")
	public Json editBranch(String id,String value){
		Json j = new Json();
		try {
			bservice.editBranch(id,value);
			j.setMsg("编辑成功！");
			j.setObj(value);
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("编辑失败！");
			log.error("编辑平台接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 编辑平台
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/edits")
	public Json editsBranch(String id,String value){
		Json j = new Json();
		try {
			bservice.editsBranch(id,value);
			j.setMsg("编辑成功！");
			j.setObj(value);
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("编辑失败！");
			log.error("编辑平台接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 删除平台
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/del",method={RequestMethod.GET,RequestMethod.POST})
	public Json delBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			bservice.delBranch(id);
			j.setMsg("删除成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("删除失败！");
			e.printStackTrace();
			log.error("删除平台接口异常！",e);
		}
		return j;
	}
	/**
	 * 停用
	 * @param session
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/ban",method={RequestMethod.POST})
	public Json banBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			bservice.banBranch(id);
			j.setMsg("停用成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("停用失败！");
			e.printStackTrace();
			log.error("停用平台接口异常！",e);
		}
		return j;
	}
	
	/**
	 * 停用
	 * @param session
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/pass",method={RequestMethod.POST})
	public Json passBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			bservice.setState(id,0);
			j.setMsg("审核通过！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("审核失败！");
			e.printStackTrace();
			log.error("审核平台接口异常！",e);
		}
		return j;
	}
	
	/**
	 * 不通过
	 * @param session
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/notpass",method={RequestMethod.POST})
	public Json notPassBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			bservice.setState(id,3);
			j.setMsg("不通过！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("不通过失败！");
			e.printStackTrace();
			log.error("不通过平台接口异常！",e);
		}
		return j;
	}
	
	/**
	 * 重置安全码
	 * @param session
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/reset",method={RequestMethod.POST})
	public Json resetBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			String s = bservice.setSecret(id);
			j.setMsg("重置成功！");
			j.setObj(s);
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("重置失败！");
			e.printStackTrace();
			log.error("重置接口异常！",e);
		}
		return j;
	}
	/**
	 * 重新提交审核
	 * @param session
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/reload",method={RequestMethod.POST})
	public Json reloadBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			bservice.reloadBranch(id);
			j.setMsg("提交审核成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("提交审核失败！");
			e.printStackTrace();
			log.error("提交审核接口异常！",e);
		}
		return j;
	}
	/**
	 * 恢复使用
	 * @param session
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/recovery",method={RequestMethod.POST})
	public Json recoveryBranch(HttpSession session,Long id){
		Json j = new Json();
		try {
			bservice.recoveryBranch(id);
			j.setMsg("恢复成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("恢复失败！");
			e.printStackTrace();
			log.error("恢复平台接口异常！",e);
		}
		return j;
	}
	
	/*****************************************/
	@RequestMapping(value="/channelpage")
	public String channelPage(HttpSession session){
		User u = (User) session.getAttribute("userinfo");
		if(null!=u){
			return "h/channel";
		}
		return "h/login";
	}
	
	
	/**
	 * 获取所有父栏目
	 * @param Session
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/parent",method=RequestMethod.GET)
	public Json getParentChannel(HttpSession Session){
		Json j = new Json();
		try {
			List<ChannelVo> vos = service.getParentChannel();
			j.setSuccess(true);
			if(vos.size()>0){
				j.setMsg("成功获取所有父栏目！");
				j.setObj(vos);
			}else{
				j.setMsg("暂无父栏目！");
			}
		} catch (Exception e) {
			j.setMsg("获取父栏目接口异常！");
			log.error("获取父栏目接口异常！",e);
			e.printStackTrace();
		}
		return j;
		
	}
	/**
	 * 获取父栏目
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/getParent",method=RequestMethod.POST)
	public String getParentChannel(HttpSession session,String aoData){
		JSONObject obj = new JSONObject();
		aoData = aoData.replaceAll("&quot;", "\"");
		String sEcho = null, sSearch = "";
		int iDisplayStart = 0;// 起始索引
		int iDisplayLength = 0;// 每页显示行数
		try {
			User u = (User) session.getAttribute("userinfo");
			if(u.getType()==1){
				JSONObject o = JSONObject.parseObject(aoData);
				sEcho = o.getString("sEcho");
				sSearch = o.getString("sSearch");
				iDisplayStart = o.getInteger("iDisplayStart");
				iDisplayLength = o.getInteger("iDisplayLength");
				if(u!=null){
					List<ChannelVo> vos = service.getParentChannel(sSearch, iDisplayStart,iDisplayLength);
					obj.put("sEcho", sEcho);
					
					obj.put("iTotalRecords", vos.size());// 实际的行数
					obj.put("iTotalDisplayRecords", service.countParentChannel(sSearch));// 显示的行数,这个要和上面写的一样
					obj.put("aaData", vos);// 要以JSON格式返回
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return JSONArray.toJSONString(obj);
	}
	
	
	/**
	 * 获取子栏目
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/child",method=RequestMethod.POST)
	public String getChildChannel(HttpSession session,String aoData,String id,String bid){
		if("".equals(id)||null==id){
			return null;
		}
		JSONObject obj = new JSONObject();
		aoData = aoData.replaceAll("&quot;", "\"");
		String sEcho = null, sSearch = "";
		int iDisplayStart = 0;// 起始索引
		int iDisplayLength = 0;// 每页显示行数
		try {
			User u = (User) session.getAttribute("userinfo");
			JSONObject o = JSONObject.parseObject(aoData);
			sEcho = o.getString("sEcho");
			sSearch = o.getString("sSearch");
			iDisplayStart = o.getInteger("iDisplayStart");
			iDisplayLength = o.getInteger("iDisplayLength");
			if(u!=null){
				if(bid==null||bid.equals("")){
					bid="0";
				}
				List<ChannelVo> vos = service.getChildChannel(sSearch, iDisplayStart,iDisplayLength,id,new Long(bid));
				obj.put("sEcho", sEcho);
				obj.put("iTotalRecords", vos.size());// 实际的行数
				obj.put("iTotalDisplayRecords", service.countChildChannel(sSearch,id));// 显示的行数,这个要和上面写的一样
				obj.put("aaData", vos);// 要以JSON格式返回
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return JSONArray.toJSONString(obj);
	}
	
	/**
	 * 申请栏目
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/apply",method=RequestMethod.POST)
	public Json applyChannel(HttpSession session,String key,String name,String bid){
		Json j = new Json();
		try {
			boolean isTrue = service.applyChannel(key,name,new Long(bid));
			if(isTrue){
				j.setSuccess(true);
			}
		} catch (Exception e) {
			log.error("申请栏目使用权限接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 暂停使用
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/stop",method=RequestMethod.POST)
	public Json stopChannle(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			service.setChannelState(key,new Long(bid),1);
			j.setSuccess(true);
			j.setMsg("暂停使用成功！");
		} catch (Exception e) {
			j.setMsg("暂停使用失败！");
			log.error("暂停使用接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 恢复使用
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/recovery",method=RequestMethod.POST)
	public Json recoveryChannle(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			service.setChannelState(key,new Long(bid),0);
			j.setSuccess(true);
			j.setMsg("恢复使用成功！");
		} catch (Exception e) {
			j.setMsg("恢复使用失败！");
			log.error("恢复使用接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 取消申请
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/cancel",method=RequestMethod.POST)
	public Json cancelChannle(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			service.setChannelState(key,new Long(bid),-1);
			j.setSuccess(true);
			j.setMsg("取消申请成功！");
		} catch (Exception e) {
			j.setMsg("取消申请失败！");
			log.error("取消申请接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 重新申请
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/reload",method=RequestMethod.POST)
	public Json reloadChannle(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			service.setChannelState(key,new Long(bid),2);
			j.setSuccess(true);
			j.setMsg("重新申请成功！");
		} catch (Exception e) {
			j.setMsg("重新申请失败！");
			log.error("重新申请接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 取消权限申请
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/cancelapply",method=RequestMethod.POST)
	public Json cancelApply(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			boolean isTrue = service.cancelApplyChannel(key,new Long(bid));
			if(isTrue){
				j.setSuccess(true);
			}
		} catch (Exception e) {
			log.error("取消栏目使用权限接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 暂停使用
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/stopapply",method=RequestMethod.POST)
	public Json stopApply(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			boolean isTrue = service.stopApplyChannel(key,new Long(bid));
			if(isTrue){
				j.setSuccess(true);
			}
		} catch (Exception e) {
			log.error("暂停栏目使用权限接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 恢复使用
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/recoveryapply",method=RequestMethod.POST)
	public Json recoveryApply(HttpSession session,String key,String bid){
		Json j = new Json();
		try {
			boolean isTrue = service.recoveryApplyChannel(key,new Long(bid));
			if(isTrue){
				j.setSuccess(true);
			}
		} catch (Exception e) {
			log.error("恢复栏目使用权限接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	

	/**
	 * 跳转到栏目申请页面
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/branchchannelpage")
	public String branchChannelPage(HttpSession session){
		User u = (User) session.getAttribute("userinfo");
		if(null!=u&&u.getType()==0){
			return "h/branchchannel";
		}
		return "h/login";
	}
	
	@ResponseBody
	@RequestMapping(value="/getbranchchannel",method={RequestMethod.GET,RequestMethod.POST})
	public Json getBranchChannel(HttpSession session,String aoData){
		Json j = new Json();
		try {
			aoData = aoData.replaceAll("&quot;", "\"");
			User u = (User) session.getAttribute("userinfo");
			JSONObject o = JSONObject.parseObject(aoData);
			String search = o.getString("sSearch");
			Integer start = o.getInteger("iDisplayStart");
			Integer length = o.getInteger("iDisplayLength");
			List<BranchChannelVo> vos = service.getBranchChannel(search, start,length,u);
			Map<String,Object> m = new HashMap<String,Object>();
			m.put("sEcho", o.getString("sEcho"));
			m.put("iTotalRecords", vos.size());
			m.put("iTotalDisplayRecords",service.countBranchChannel(search,u));
			m.put("aaData", vos);// 要以JSON格式返回
			if(m.size()>0){
				j.setObj(m);
				j.setSuccess(true);
				j.setMsg("成功获取平台列表！");
			}else{
				j.setMsg("该用户暂无平台列表！");
				j.setSuccess(true);
			}
		} catch (Exception e) {
			j.setMsg("获取平台列表接口异常！");
			log.error("获取平台列表接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	
	/**
	 * 通过申请审核
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/adopt",method={RequestMethod.POST})
	public Json adoptChannel(HttpSession session,Long id){
		Json j = new Json();
		try {
			service.setState(id,0);
			j.setMsg("申请通过！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("接口异常！");
			log.error("申请栏目权限接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 不通过申请审核
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/channel/notpass",method={RequestMethod.POST})
	public Json notPassChannel(HttpSession session,Long id){
		Json j = new Json();
		try {
			service.setState(id,3);
			j.setMsg("申请通过！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("接口异常！");
			log.error("申请栏目权限接口异常！",e);
			e.printStackTrace();
		}
		return j;
	}
}
